using System;
using System.Globalization;
using GammaJul.ReSharper.GammaXaml.Psi.Xaml;
using JetBrains.Annotations;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Xaml.Impl.Tree;

namespace GammaJul.ReSharper.GammaXaml.Highlightings.Xaml {

	public abstract class MeaninglessAttachedSetterHighlightingBase : DeadCodeSetterHighlightingBase {
		private readonly IMethod _attachedSetter;

		[NotNull]
		public IMethod AttachedSetter {
			get { return _attachedSetter; }
		}

		public override bool IsValid() {
			return base.IsValid() && _attachedSetter.IsValid();
		}

		public override string ToolTip {
			get {
				ITypeElement containingType = AttachedSetter.GetContainingType();
				return String.Format(
					CultureInfo.CurrentCulture,
					"'{0}.{1}' only has a meaning on {2}",
					containingType != null ? containingType.ShortName : null,
					AttachedSetter.GetExpectedDpName(),
					GetToolTipEnd());
			}
		}

		[CanBeNull]
		protected abstract string GetToolTipEnd();

		protected MeaninglessAttachedSetterHighlightingBase([NotNull] IPropertySetter propertySetter, [NotNull] IMethod attachedSetter)
			: base(propertySetter) {
			if (attachedSetter == null)
				throw new ArgumentNullException("attachedSetter");

			_attachedSetter = attachedSetter;
		}
	}

}